{% extends "repo/repo.html" %}

{% block subcontainer %}

<div class="commits bubble">
  {% if commit %}
  <div class="commit colspan">
    <div class="commiter span">
      <figure class="avatar"><img src="https://gravatar.com/avatar/{{commit.author_imgurl}}?s=40" alt="{{commit.committer_name}}"></figure>
      <div class="summary">
        <p class="msg"><a href="#">{{commit.commit_message|truncatechars:80}}</a></p>
        <p class="meta">
          {% if commit.real_committer_name %}
            <a href="/{{commit.real_committer_name}}/">{{commit.committer_name}}</a>
          {% else %}
            <span>{{commit.committer_name}}</span>
          {% endif %}
          <span class="date unixtime">{{commit.committer_date}}</span>
        </p>
      </div>
    </div>
    <div class="hash span">
      <span>父对象</span>
      {% for parent_commit_hash in commit.parent_commit_hash %}
        <a href="/{{user_name}}/{{repo_name}}/commit/{{parent_commit_hash}}/" class="btn btn-mini parent_commit_hash">{{parent_commit_hash}}</a>
      {% endfor %}
    </div>
  </div>
  <ul class="nav nav-tabs">
    {% for parent_commit_hash in commit.parent_commit_hash %}
      <li class="hash"><a href="#diff_{{parent_commit_hash}}" data-toggle="tab">{{parent_commit_hash}}</a></li>
    {% endfor %}
  </ul>
  {% else %}
  <div class="commit">
    <p class="alert alert-error"><i class="icon-bell"></i><em>没有找到该 Commit</em></p>
  </div>
  {% endif %}
  <div class="tab-content">
    <pre class="alert alert-info">$ git diff <span id="parent-commit-hash"></span>...{{commit_hash}}</pre>
    {% for parent_commit_hash in commit.parent_commit_hash %}
      <div id="diff_{{parent_commit_hash}}" class="tab-pane"></div>
    {% endfor %}
  </div>

</div>
{% endblock %}

{% block subjs %}
<script>
  $(function(){
    function loadDiff(user_name, repo_name, parent_commit_hash){
      var repoComparer = new RepoComparer(user_name, repo_name, '', '');
      var parent_commit_hash_span = $('#parent-commit-hash');
      repoComparer.from_refs = parent_commit_hash; repoComparer.to_refs = commit_hash; repoComparer.path = '.';
      repoComparer.loadDiff($('#diff_' + parent_commit_hash), null, null);
      repoComparer.registerLineContextEvent($('#diff_' + parent_commit_hash));
    }
    var commit_hash = '{{commit_hash}}';
    {% for parent_commit_hash in commit.parent_commit_hash %}
      loadDiff('{{user_name}}', '{{repo_name}}', '{{parent_commit_hash}}');
    {% endfor %}

    $('.commits .nav-tabs li:eq(0)').addClass('active');

    $('#parent-commit-hash').text($('.commits .nav-tabs li:eq(0)').find('a').text());

    $('[data-toggle="tab"]').click(function(){
      var parentCommitHash = $(this).text();
      $('#parent-commit-hash').text(parentCommitHash);
    });

    $('[id^=diff_]').first().addClass('active');
  });
</script>
{% endblock %}
